package com.myrobot.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.filechooser.FileFilter;

public class MainWindow extends JFrame {
	public static final String ACT_MENU_COMMAND_FILE = "act_menu_command_file";
	private JMenuBar mMenuBar = null;
	private JMenu mMenuFile = null;
	private JMenuItem  mCommandFile = null;
	public MainWindow() {
		setBounds(100, 100, 800, 600);
		mMenuBar = new JMenuBar();
	    setJMenuBar(mMenuBar);
	    mMenuFile = new JMenu("File");
	    mMenuFile.setMnemonic('F'); 
	    mMenuBar.add(mMenuFile);
	    mCommandFile = new JMenuItem("Command File");
	    mCommandFile.setActionCommand(ACT_MENU_COMMAND_FILE);
	    mMenuFile.add(mCommandFile);
//		setVisible(true);
//		setExtendedState(JFrame.NORMAL);
//		setExtendedState(JFrame.ICONIFIED);
	}
	
	private void loadCommandFile(File f) {
		
	}
	
	private ActionListener mActionListener = new ActionListener() {

		public void actionPerformed(ActionEvent e) {
			if (ACT_MENU_COMMAND_FILE.equals(e.getActionCommand())) {
				JFileChooser fileChooser = new JFileChooser();
				fileChooser.setFileFilter(new FileFilter() {
					
					@Override
					public String getDescription() {
						// TODO Auto-generated method stub
						return null;
					}
					
					@Override
					public boolean accept(File f) {
						// TODO Auto-generated method stub
						return f.getName().endsWith(".json");
					}
				});
				fileChooser.showOpenDialog(null);
				File f = fileChooser.getSelectedFile();
				if(f !=null && f.exists()) {
					loadCommandFile(f);
				}
			}
		}
	};
}
